{% macro render_nav_item(endpoint, text, badge='') %}
    <a class="item {% if request.endpoint and request.endpoint == endpoint %}active{% endif %}"
       href="{{ url_for(endpoint, **kwargs) }}">
       {{text}}
    </a>
{% endmacro %}

{% macro render_messages(messages=None, container=False, transform={
     'critical': 'negative',
     'error': 'negative',
     'info': 'info',
     'warning': 'warning',
     'debug': ' ',
     'notset': ' ',
     'message': ' ',
     'negative':'danger',
     'danger':'negative'
    }, default_category='primary', dismissible=False, dismiss_animate=False) -%}
   
    {% with messages = messages or get_flashed_messages(with_categories=True) -%}
	    {% if messages -%} 
	    	{# don't output anything if there are no messages #}
		    {% for cat, msg in messages %}
		        <div class="ui {{ transform.get(cat.lower(), cat or default_category) }} message">
		  			<i class="close icon"></i>
		  				<div class="header">
		           			{{ msg }}
		         		</div>
		        </div>
		    {%- endfor -%}
	    {% endif -%}
    {% endwith -%}
{% endmacro -%}
{% macro _arg_url_for(endpoint, base) %}
    {%- with kargs = base.copy() -%}
        {%- do kargs.update(kwargs) -%}
        {{ url_for(endpoint, **kargs) }}
    {%- endwith %}
{% endmacro %}

{% macro render_pagination(pagination) %}
	{% set url_args = {} %}
	{% do url_args.update(request.args) %}
	<div class="ui pagination menu">
		{% if pagination.has_prev %}
			<a class="item" href="{{_arg_url_for(request.endpoint, url_args, page=1)}}">
				<i class="angle double left icon"></i>
			</a>
			<a class="item" href="{{_arg_url_for(request.endpoint, url_args, page=pagination.prev_num)}}">
				<i class="angle left icon"></i>
			</a>
		{% endif %}
		{% for page in pagination.iter_pages() %}
			{% if page %}
				{% if page != pagination.page %}
					<a class="item" href="{{_arg_url_for(request.endpoint, url_args, page=page)}}">
				    	{{page}}
				    </a>
				{% else %}
					<a class="active item" href="{{_arg_url_for(request.endpoint, url_args, page=page)}}">
				    	{{page}}
				    </a>
				{% endif %}
			{% else %}
				<div class="disabled item">
					...
				</div>
			{% endif %}
		{% endfor %}
		{% if pagination.has_next %}
			<a class="item" href="{{_arg_url_for(request.endpoint, url_args, page=pagination.next_num)}}">
				<i class="angle right icon"></i>
			</a>
			<a class="item" href="{{_arg_url_for(request.endpoint, url_args, page=pagination.pages)}}">
				<i class="angle double right icon"></i>
			</a>
		{% endif %}
	</div>
{% endmacro %}